from CreateDirector import CreateDirector

class WriteDao:
    def __init__(self,entityName,packRoot,dir='./out/dao'):
        self.entityName = entityName
        self.dir = dir
        self.list = [
            'package %s.dao;\n' % (packRoot),
            '\n',
            'import %s.entity.%s;\n' % (packRoot, entityName),
            '\n',
            'public interface %sDao extends BaseDao<%s, Integer>{\n\n\n}\n' % (entityName, entityName)
        ]

    def writeDao(self):
        try:
            with open(self.dir + '/' + self.entityName + 'Dao.java', 'w') as f:
                f.writelines(self.list)
                f.close()
                print(self.entityName + 'Dao.java生成！')
        except FileNotFoundError as e:
            print('%s 目录不存在，开始创建' % self.dir)
            createDir = CreateDirector(self.dir)
            createDir.create()
            self.writeDao()

if __name__ == '__main__':
    writeDao = WriteDao('fef','fef')
    writeDao.writeDao()